package com.xuzao.developer.dao.impl;

import com.xuzao.developer.tools.base.BaseServiceSupport;
import com.xuzao.developer.base.model.GridFieldSys;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xuzao.developer.base.criteria.GridFieldSysCriteria;
import com.xuzao.developer.tools.entity.Pager;
import com.xuzao.developer.mapper.GridFieldSysMapper;
import com.xuzao.developer.dao.GridFieldSysDao;

import javax.annotation.Resource;

import com.xuzao.developer.dto.GridFieldSysDTO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;


/**
 * @description 
 * @author xuzao
 * @date 2019-09-03 17:12:57
 **/
@Service("gridFieldSysDao")
public class GridFieldSysDaoImpl extends BaseServiceSupport<GridFieldSys> implements GridFieldSysDao {

	@Resource
	private GridFieldSysMapper gridFieldSysMapper;


	@Override
	public PageInfo<GridFieldSys> list(GridFieldSysDTO dto, Pager pager) {
		GridFieldSysCriteria criteria = this.assemblyQuerycond(dto);
		if (null != pager) {
			if (null != pager.getPageCurrent() && null != pager.getNumPerPage()) {
				PageHelper.startPage(pager.getPageCurrent(), pager.getNumPerPage());
			}
		}
		PageInfo<GridFieldSys> pageInfo = new PageInfo<>(this.gridFieldSysMapper.selectByExample(criteria));
		return pageInfo;
	}

	//通用查询方法条件组装
	public GridFieldSysCriteria assemblyQuerycond(GridFieldSysDTO dto) {
		GridFieldSysCriteria criteria = new GridFieldSysCriteria();
		GridFieldSysCriteria.Criteria c = criteria.createCriteria();

		if (null != dto) {
			if (dto.getGridId()!=null){
				c.andGridIdEqualTo(dto.getGridId().toString());
			}
			if (StringUtils.isNotBlank(dto.getFieldCaption())){
				c.andFieldCaptionLike("%"+dto.getFieldCaption()+"%");
			}
			if (StringUtils.isNotBlank(dto.getFieldName())){
				c.andFieldNameLike("%"+dto.getFieldName()+"%");
			}
			if (StringUtils.isNotBlank(dto.getGridName())){
				c.andGridNameLike("%"+dto.getGridName()+"%");
			}
		}
		return criteria;
	}
}